﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Game3 : MonoBehaviour
{

    #region Others
    public TaDiao taDiao = null;
    public GameObject curser;
    public CameraPathBezierAnimator cameraPathAni;
    public GameObject smallPlane;
    public GameObject cameraRig;
    public GameObject bigPlane; 
    public MyCameraEffect cameraEffect;
    public EndTip endTip;
    CameraRotater rotater;
    public AudioClip clip;
    public InputController leftController;
    public InputController rightController;
    #endregion

    void Awake()
    {
        PlayerPrefs.SetString("sceneName", "Scene3");
        rotater = cameraRig.AddComponent<CameraRotater>();
    }


    void Start()
    {
        curser.GetComponent<DistanceEvent>().OnNearEvent.AddListener(OnNearCurser); 
        taDiao.OnHitPlayer += Player_OnHitPlayer;
        taDiao.OnHitGround += TaDiao_OnHitGround;
        cameraEffect.OnCancleBlack += CameraEffect_OnCancleBlack;
        StartPlay();
        SoundManager.instance.PlayBGMusic(clip);


    }

    private void CameraEffect_OnCancleBlack()
    {
        endTip.ShowTip(TipWords.game3_wutidaji);
    }

    private void TaDiao_OnHitGround()
    {

        rotater.StopRotate();
        SoundManager.instance.Play("luodigangguan");
        MyControllerManager.instance.EnableController();
        cameraEffect.PlayDeadBlood();
        leftController.DisAbleTeleProt();
        rightController.DisAbleTeleProt();
    }

    /// <summary>
    /// 两种模式切换
    /// </summary>

    private void StartPlay()
    {
        if (PlayerPrefs.GetString("mode") == "教育模式")
        {
            Debug.Log("开始教育模式");
            Debug.Log("当前场景为：" + PlayerPrefs.GetString("sceneName"));
            cameraPathAni.Play();
            MyControllerManager.instance.DisableController();
        }
        else
        {
            Debug.Log("开始体验模式");
            Debug.Log("当前场景为：" + PlayerPrefs.GetString("sceneName"));
        }
    }


    /// <summary>
    /// 击中玩家
    /// </summary>
    private void Player_OnHitPlayer()
    {
        SoundManager.instance.Play("jianjiaosheng_Femal");
        BoxCollider box= cameraRig.AddComponent<BoxCollider>();
        box.size = new Vector3(1.3f, 2f, 1.3f);
        box.center = new Vector3(0, 1.9f, 0);
        Rigidbody rig= cameraRig.AddComponent<Rigidbody>();
        rig.collisionDetectionMode = CollisionDetectionMode.Continuous;
        smallPlane.SetActive(false);
        bigPlane.SetActive(false);
        rotater.StartRotate();
        curser.SetActive(false);

    }


    /// <summary>
    /// 靠近了Curser
    /// </summary>
    private void OnNearCurser()
    {
        leftController.DisAbleTeleProt();
        rightController.DisAbleTeleProt();
        curser.SetActive(false);
        taDiao.PlayAnimation();
    }


}
